﻿using System.IO;

namespace Common.Files
{
    public class ImgHelper
    {
        /// <summary>
        /// 验证是否为图片(jpg,gif,BMP,PNG)
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static bool IsImgFile(Stream reader)
        {
            BinaryReader r = new BinaryReader(reader);
            string fileclass = "";
            byte buffer;
            buffer = r.ReadByte();
            fileclass = buffer.ToString();
            buffer = r.ReadByte();
            fileclass += buffer.ToString();
            //r.Dispose();
            reader.Position = 0;
            if (fileclass == "255216" || fileclass == "7173" || fileclass == "6677" || fileclass == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
